<template>
  <el-card shadow="never" class="aui-card--fill">
    <el-form ref="form" :inline="true" :model="dataForm">
      <el-form-item>
        <el-input
          v-model="dataForm.keyWord"
          placeholder="请输入专题名称"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="reset()">重置</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <el-button type="primary" @click="add()">新增</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="deleteAll()">{{
          $t("deleteBatch")
        }}</el-button>
      </el-form-item> -->
    </el-form>
    <div class="table-top">
      <div class="left">
        <div class="top-line"></div>
        专题配置列表
      </div>
      <div class="right">
        <div class="table-top-btn" @click="add()">新增</div>
        <div class="table-top-btn" @click="deleteAll()">删除</div>
      </div>
    </div>
    <el-table
      ref="table"
      v-loading="dataListLoading"
      :data="dataList"
      border
      stripe
      @selection-change="dataListSelectionChangeHandle"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      ></el-table-column>

      <el-table-column
        prop="topicName"
        label="专题名称"
        header-align="center"
        align="center"
      ></el-table-column>
      <el-table-column label="图标" header-align="center" align="center">
        <template slot-scope="scope">
          <img style="width: 100px; height: 100px" :src="scope.row.icon" />
        </template>
      </el-table-column>
      <el-table-column
        prop="division"
        label="所属模块"
        header-align="center"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="sort"
        label="专题排序"
        header-align="center"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="remark"
        label="备注信息"
        header-align="center"
        align="center"
      ></el-table-column>
      <el-table-column label="状态" header-align="center" align="center">
        <template slot-scope="scope">
          {{ status.filter((f) => f.value == scope.row.status)[0].label }}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建日期"
        header-align="center"
        align="center"
      ></el-table-column>

      <el-table-column
        :label="$t('handle')"
        fixed="right"
        header-align="center"
        align="center"
        width="150"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="edit(scope.row)"
            >修改</el-button
          >

          <el-button type="text" size="small" @click="showConfig(scope.row)"
            >指标配置</el-button
          >

          <el-button type="text" size="small" @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :current-page="page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="limit"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="pageSizeChangeHandle"
      @current-change="pageCurrentChangeHandle"
    >
    </el-pagination>
    <AddEdit ref="AddEdit" @cancel="getDataList()" />
    <Config ref="Config" @cancel="getDataList()" />
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddEdit from "./components/add_edit.vue";
import Config from "./components/config.vue";
export default {
  mixins: [mixinViewModule],
  components: { AddEdit, Config },
  data() {
    return {
      moduleTree: [],
      mixinViewModuleOptions: {
        getDataListURL: "/cgjybzTopicConfiguration/getTopicConfigurationList",
        getDataListIsPage: true,
        deleteURL: "/cgjybzTopicConfiguration/deleteTopicConfiguration",
        deleteIsBatch: true,
      },
      dataForm: {
        keyWord: null,
      },
      status: [
        {
          label: "停用",
          value: 0,
        },
        {
          label: "正常",
          value: 1,
        },
      ],
    };
  },
  created() {
    this.getDataList();
  },
  methods: {
    showConfig(ev) {
      this.$refs["Config"].showModal(ev);
    },
    // 重置
    reset() {
      this.dataForm = {
        keyWord: null,
      };
      this.getDataList();
    },
    add() {
      this.$refs["AddEdit"].showModal("add");
    },
    edit(ev) {
      this.$refs["AddEdit"].showModal("edit", ev);
    },
    del(id) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$http
          .get(`/cgjybzTopicConfiguration/deleteTopicConfiguration?ids=${id}`)
          .then((res) => {
            this.$message.success(res.data.msg);

            this.getDataList();
          });
      });
    },
    deleteAll() {
      if (this.dataListSelections.length == 0) {
        this.$message.warning("请选择专题");
      } else {
        this.$confirm("此操作将永久删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.$http
            .get(
              `/cgjybzTopicConfiguration/deleteTopicConfiguration?ids=${this.dataListSelections
                .reduce((prev, cur) => {
                  prev.push(cur.id);
                  return prev;
                }, [])
                .join(",")}`
            )
            .then((res) => {
              this.$message.success(res.data.msg);
              this.getDataList();
            });
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.blue {
  color: #3d76cc;
}
</style>
